package com.duke;

import org.springframework.util.DigestUtils;

import java.nio.charset.StandardCharsets;
import java.util.Random;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

/**
 * @Author: duke
 * @Description:
 * @Date: 2022/3/23 10:27 上午
 */
public class HighCPUApplication {

    private static byte[] payload = IntStream.rangeClosed(1,10000).mapToObj(__ -> "a").collect(Collectors.joining("")).getBytes(StandardCharsets.UTF_8);

    private static Random random = new Random();

    public static void main(String[] args) {
        HighCPUApplication.task();
    }

    private static void task() {
        do{
            HighCPUApplication.doTask(random.nextInt(100));
        }while (true);
    }

    private static void doTask(int i) {
        if(i == 0){
            IntStream.rangeClosed(1,10000).parallel().forEach(j -> DigestUtils.md5DigestAsHex(payload));
        }
    }
}
